package cn.csxw.openchina.ui.fragment.exerciseFragment;

import android.os.Bundle;
import android.support.annotation.Nullable;

import javax.inject.Inject;

import cn.csxw.openchina.base.BaseRecAdapter;
import cn.csxw.openchina.base.BaseRefreshFragment;
import cn.csxw.openchina.constant.Constant;
import cn.csxw.openchina.dagger2.component.DaggerMyRecentlyFragmentComponent;
import cn.csxw.openchina.dagger2.module.MyRecentlyFragmentModules;
import cn.csxw.openchina.dagger2.presenter.MyRecentlyFragmentPresenter;
import cn.csxw.openchina.ui.adapter.MyRecentlyAdapter;
import cn.csxw.openchina.utils.Global;

/**
 * 我的活动
 */

public class MyExerciseFragment extends BaseRefreshFragment {

    public MyRecentlyAdapter mAdapter;
    @Inject
    MyRecentlyFragmentPresenter mMyRecentlyFragmentPresenter;
    private String mUserUid;

    @Override
    protected BaseRecAdapter getAdapter() {
        if (mAdapter == null) {
            mAdapter = new MyRecentlyAdapter();
        }
        return mAdapter;
    }

    @Override
    public void doRefresh() {
        mMyRecentlyFragmentPresenter.callNetWork(mUserUid, 0, 20);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        setOnRefreshListener(onRefreshListener);
        DaggerMyRecentlyFragmentComponent.builder()
                .myRecentlyFragmentModules(new MyRecentlyFragmentModules(this))
                .build()
                .inject(this);
        mUserUid = Global.getUserUid(Constant.USER_UID);
        mMyRecentlyFragmentPresenter.callNetWork(mUserUid, 0, 20);
        Global.onNetworkStateListener(mMyRecentlyFragmentPresenter, this);
    }

    private int pageIndex = 0;
    OnRefreshListener onRefreshListener = new OnRefreshListener() {
        @Override
        public void onUpLoadMore() {
            pageIndex++;
            mMyRecentlyFragmentPresenter.callNetWork(mUserUid, pageIndex, 20);
        }
    };
}
